 <?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class PageController extends AppPageController
{	

	var $rb;
	var $rp;
	
	var $manager;
	
	
	function PageController($controller, $class_name) {
		
		$this->init($controller, $class_name);
	}
	
	
	
	function init(&$controller, $class_name) {
		
		require_once $controller->working_dir . 'inc/'.$class_name . '.php';
		require_once $controller->working_dir . 'inc/'.$class_name . 'Model.php';
		
		
		// initialize objects
		// $this->controller = &$controller;
		
		//$this->rq = &new RequestData($_GET);
		//$this->rp = &new RequestData($_POST);
		
		//$this->obj = &new $class_name;
		
		//$class_name = $class_name . 'Model';
		//$this->manager = &new $class_name;
		//$this->manager->checkPriv($priv, $this->action, $this->rq->id);		
	}
	
	
	function execute($class_name) {
		
	}
	
	
	function execute() {
		
	}
}


$page = new PageController($controller, 'User');

$obj = new User;

$manager = &new KBEntryModel();
$manager->checkPriv($priv, $controller->action, @$rq->id);


switch ($controller->action) {
case 'delete': // ------------------------------
	 
	$manager->delete($page->request('id'));
	$controller->go();

	break;
	

case 'status': // ------------------------------
	
	$manager->status($rq->status, $rq->id);
	$controller->go();

	break;

	
case 'update': // ------------------------------
case 'insert': // ------------------------------

	
	if(isset($rp->submit)) {
		
		$is_error =& $obj->validate($rp->vars);
		
		if($is_error) {
			$rp->stripVars(true);
			
			$obj->set($rp->vars);
			$obj->setCategory(@$rp->vars['category']);
		
		} else {
			$rp->stripVars();
			
			$obj->set($rp->vars);
			$obj->setCategory($rp->vars['category']);
			
			$manager->save($obj);
			
			$controller->go();
		}
		
	
	} elseif($controller->action == 'update') {
		
		$obj->set($manager->getById($rq->id));
		$obj->setCategory($manager->getCategoryById($rq->id));		
	}
	
	
	$view = &$controller->getView($obj, $manager, 'KBEntryView_form');

	break;


default: // ------------------------------------
	
	$view = &$controller->getView($obj, $manager, 'KBEntryView_list');
}
?>